-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow non octal decimal escape before use strict #12366
Disallow non octal decimal escape before use strict #12366
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/33964/ |
@@ -1 +1,2 @@ | |||
|
|||
language/literals/string/legacy-non-octal-escape-sequence-8-strict-explicit-pragma.js(default) | |||
language/literals/string/legacy-non-octal-escape-sequence-9-strict-explicit-pragma.js(default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bug is caught by these two failing test262 tests.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 22c4c17:
|
2ac4617
to
ae30cba
Compare
"use strict"; | ||
04; | ||
05; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are moved to https://github.com/babel/babel/pull/12366/files#diff-cd40ee2fb191cbf29a8bbfc49ae7471de322ff395f79acf129d3f9cd3832a688
So this test is focused on numeric escape sequence only.
// todo(JLHwung): set strictErrors to null and avoid recording string errors | ||
// after a non-directive is parsed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to do this here or in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer a separate PR since alternatively, todo is pronounced as never-do. 😛
Legacy octal or numeric escapes are discouraged, I feel like it is okay to leave it as-is.
ae30cba
to
22c4c17
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
() => { "\8";"\9";"use strict"; }
(REPL)This PR also refactors how we track numeric escape (though named as
octalPositions
). Currentlythis.state.octalPositions
is reset wheneverthis.nextToken
is called, this is unnecessary and can be avoided by only reset when a) directives are allowed in blocks and b) we have not yet seen a non-directive parsed. I renamedoctalPositions
tostrictErrors
since we need to track two errors in this PRHowever I think we should throw StrictNumericEscape for both
\8
and\01
, since the latter is not an octal literal but an octal escape sequence, which falls into numeric escape. I have update the error message in this PR.This PR also avoids reparsing the numeric/string literal after strict directive in
setState
, since the octal error is now tracked instrictErrors
.Last this PR extracts legacy octal literal test cases from string escape sequence tests.
@kaicataldo Feedbacks are welcome since this PR is a follow-up to & inspired from #11188.